/**
 * Copyright (C), 2015-2020, XXX有限公司
 * FileName: MyUserService
 * Author:   吴建森
 * Date:     2020/12/2 11:50
 * Description:
 * History:
 * <author>吴建森      <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.sen.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sen.entity.EmpEntity;
import com.sen.entity.MyUserDetails;
import com.sen.entity.UserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

/**
 * 〈一句话功能简述〉<br>
 * 〈〉
 *
 * @author 吴建森
 * @create 2020/12/2
 * @since 1.0.0
 */
@Component
public class MyUserService implements UserDetailsService {

    @Autowired
    private EmpService empService;

    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        EmpEntity emp = empService.getOne(new QueryWrapper<EmpEntity>().eq("username", s));
        if (emp == null){
            throw new UsernameNotFoundException("未找到用户");
        }
        //查询角色
        MyUserDetails myUserDetails = new MyUserDetails();
        myUserDetails.setUsername(emp.getUsername());
        myUserDetails.setPassword(emp.getPassword());
        myUserDetails.setEid(emp.getEid());
        return myUserDetails;
    }
}
